home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bc_ti.zip / TI735.ASC < prev    next >
Text File  |  1992-02-25  |  2KB  |  67 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  735
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/1
  12.  
  13.     TITLE  :  Determining Program Size
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.   /**********************************************************************
  21.  
  22.   The size of a program cannot be determined statically because the
  23.   the  stack and near heap are sized dynamically at run time.  The
  24.   load size  specified in the EXE header is incorrect for this
  25.   reason.  The only way  to accurately determine the program image
  26.   size is to check it at run time.
  27.  
  28.   This program will get the current size of the program image in
  29.   memory. This size will change dynamically as the program acquires
  30.   memory from and releases memory to DOS.  This in formation is
  31.   stored in the Memory Control Block (MCB).  The MCB begins one
  32.   paragraph (16 bytes) before the Program Segment Prefix (PSP).
  33.   The current program size is stored at offset 0x3 from the
  34.   beginning of the MCB.  Offset 0x3 represents the size in
  35.   paragraphs therefore it must be multiplied by 16 to obtain the
  36.   size in bytes.
  37.  
  38.  
  39.   WRITTEN BY
  40.        Jerry Shockley      9/19/91
  41.  
  42.   **********************************************************************/
  43.   #include <dos.h>
  44.  
  45.   unsigned _stklen = 63000u;  //This size can be changed to see the
  46.   size
  47.                               // size change.
  48.  
  49.   void main()
  50.   {
  51.      unsigned far *size;
  52.  
  53.      size = MK_FP( _psp - 1, 0x03 );
  54.      printf("\nSize of program in memory = %l0u", (unsigned long)
  55.   (*size) * 16 );
  56.   }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.